package bsh.dyn;

import bsh.BytecodeGenerator;
import bsh.CompiledScript;

/**
 * Adapts arguments to some other types, if necessary
 * 
 * @author takeshi
 */
public interface ArgumentsAdaptor extends BytecodeGenerator {

    /**
     * The types that this adaptor will transform into
     * 
     * @return array {@link Class}
     */
    Class<?>[] targetTypes();

    /**
     * Actually adapts the arguments and returns an array with the adapted arguments
     * 
     * @param script {@link CompiledScript}
     * @param original Object[]
     * @return Object[]
     */
    Object[] adaptArguments(CompiledScript script, Object[] original);

    /**
     * Adapts arguments into a destination array
     * 
     * @param script {@link CompiledScript}
     * @param original Object[]
     * @param destination Object[]
     */
    void adaptArgumentsInto(CompiledScript script, Object[] original, Object[] destination);

    /**
     * Used to tie-break
     * 
     * @return int
     */
    int weight();

    /**
     * @return <code>true</code> if this {@link ArgumentsAdaptor} can generate bytecode
     */
    boolean isCompilable();
}
